package com.lemon.secondhandplatform.ui.util;

import android.content.Context;
import android.widget.Toast;

/**
 * Toast工具类
 */
public class ToastUtils {

    private static Context context;
    private static Toast toast;

    /**
     * 注册上下文环境
     *
     * @param context
     */
    public static void register(Context context) {
        ToastUtils.context = context;
    }

    public static void show(String message) {
        show(message, Toast.LENGTH_SHORT);
    }

    public static void show(String message, int duration) {
        if (context == null) {
            throw new NullPointerException("ToastUtils尚未注册，请调用ToastUtils.register(Context context)方法完成注册");
        }

        if (toast == null) {
            toast = Toast.makeText(context, null, duration);
        }

        toast.setText(message);
        toast.show();
    }

}
